using System.Collections;
using System.Collections.Generic;
using QFramework;
using UnityEngine;
namespace ProjectSurvivor
{
    public class Global : Architecture<Global>
    {
        ///经验值
        public static BindableProperty<int> Exp = new BindableProperty<int>(0);
        public static BindableProperty<int> Hp = new BindableProperty<int>(3);
        public static BindableProperty<int> MaxHp = new BindableProperty<int>(3);
        public static BindableProperty<int> Coin = new BindableProperty<int>(0);
        public static BindableProperty<int> Level = new BindableProperty<int>(1);

        public static BindableProperty<float> CurrentSeconds = new BindableProperty<float>(0);
        public static BindableProperty<float> SimpleAbilityDamage = new BindableProperty<float>(1);

        public static BindableProperty<float> SimpleAbilityDuration = new BindableProperty<float>(1.5f);

        public static BindableProperty<float> CoinPercent = new BindableProperty<float>(0.05f);
        public static BindableProperty<float> ExpPercent = new BindableProperty<float>(0.3f);
        [RuntimeInitializeOnLoadMethod]
        public static void AutoInit()
        {
            ResKit.Init();
            UIKit.Root.SetResolution(width: 1920, height: 1080, 1);
            Global.MaxHp.Value = PlayerPrefs.GetInt(nameof(MaxHp), 3);
            Hp.Value = MaxHp.Value;
            Global.Coin.Value = PlayerPrefs.GetInt("coin", 0);

            Global.ExpPercent.Value = PlayerPrefs.GetFloat(nameof(ExpPercent), 0.4f);
            Global.CoinPercent.Value = PlayerPrefs.GetFloat(nameof(CoinPercent), 0.1f);
            Global.Coin.Register(coin =>
            {
                PlayerPrefs.SetInt(nameof(coin), coin);
            });

            Global.ExpPercent.Register(expPercent =>
           {
               PlayerPrefs.SetFloat(nameof(expPercent), expPercent);
           });

            Global.CoinPercent.Register(coinPercent =>
           {
               PlayerPrefs.SetFloat(nameof(coinPercent), coinPercent);
           });
            Global.MaxHp.Register(maxHp =>
            {
                PlayerPrefs.SetInt(nameof(MaxHp), maxHp);
            });
        }

        public static void ResetData()
        {
            Hp.Value = MaxHp.Value;
            Exp.Value = 0;
            Level.Value = 1;
            CurrentSeconds.Value = 0;
            SimpleAbilityDamage.Value = 1;
            SimpleAbilityDuration.Value = 1.5f;
            EnemyGenerator.EnemyCount.Value = 0;
        }
        public static int ExpToNextLevel()
        {
            return Level.Value * 5;
        }
        public static void GeneratePowerUp(GameObject gameObject)
        {
            //100% 掉落经验值
            var percent = Random.Range(0, 1f);
            if (percent <= ExpPercent.Value)
            {
                //掉落经验值
                PowerUpManager.Default.Exp.Instantiate().Position(gameObject.Position()).Show();
                return;
            }
            percent = Random.Range(0, 1f);

            if (percent < CoinPercent.Value)
            {
                PowerUpManager.Default.Coin.Instantiate().Position(gameObject.Position()).Show();
                return;
            }
            percent = Random.Range(0, 1f);
            if (percent < 0.1f)
            {
                PowerUpManager.Default.hp.Instantiate().Position(gameObject.Position()).Show();
                return;
            }

            percent = Random.Range(0, 1f);
            if (percent < 0.1f)
            {
                PowerUpManager.Default.Bomb.Instantiate().Position(gameObject.Position()).Show();
                return;
            }
            percent = Random.Range(0, 1f);
            if (percent < 0.1f)
            {
                PowerUpManager.Default.GetAllExp.Instantiate().Position(gameObject.Position()).Show();
                return;
            }
        }

        protected override void Init()
        {
            //注册模块的操作
            // XXX Model
            this.RegisterSystem(new CoinUpgradeSystem());
        }
    }
}

